﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace QYmall.Core.Model.ViewModels
{
    /// <summary>
    /// 购物车(显示)
    /// </summary>
    public class ShopCartDto : ShopCartEditDto
    {
        /// <summary>
        /// 自增ID
        /// </summary>
        [Display(Name = "自增ID")]
        public long Id { get; set; }

        // <summary>
        /// 所属商户ID
        /// </summary>
        [Display(Name = "所属商户")]
        public int MerchantId { get; set; }

        /// <summary>
        /// 所属用户ID
        /// </summary>
        [Display(Name = "所属用户")]
        public int UserId { get; set; }

        /// <summary>
        /// 商品ID
        /// </summary>
        [Display(Name = "商品ID")]
        public long GoodsId { get; set; }

        /// <summary>
        /// 商品标题
        /// </summary>
        [Display(Name = "商品标题")]
        [StringLength(512)]
        public string? Title { get; set; }

        /// <summary>
        /// 规格描述
        /// </summary>
        [Display(Name = "商品规格")]
        public string? SkuText { get; set; }

        /// <summary>
        /// 商品图片
        /// </summary>
        [Display(Name = "商品图片")]
        [StringLength(512)]
        public string? ImgUrl { get; set; }

        /// <summary>
        /// 市场价格
        /// </summary>
        [Display(Name = "市场价格")]
        [Column(TypeName = "decimal(18, 2)")]
        public decimal MarketPrice { get; set; }

        /// <summary>
        /// 销售价格
        /// </summary>
        [Display(Name = "销售价格")]
        [Column(TypeName = "decimal(18, 2)")]
        public decimal SellPrice { get; set; }

        /// <summary>
        /// 会员价格
        /// </summary>
        [Display(Name = "会员价格")]
        [Column(TypeName = "decimal(18, 2)")]
        public decimal GroupPrice { get; set; }

        /// <summary>
        /// 重量(克)
        /// </summary>
        [Display(Name = "重量(克)")]
        public int Weight { get; set; } = 0;

        /// <summary>
        /// 库存数量
        /// </summary>
        [Display(Name = "库存数量")]
        public int StockQuantity { get; set; } = 0;

        /// <summary>
        /// 状态0有效1失效
        /// </summary>
        public byte Status { get; set; } = 0;

        /// <summary>
        /// 创建时间
        /// </summary>
        [Display(Name = "创建时间")]
        public DateTime AddTime { get; set; } = DateTime.Now;
    }

    /// <summary>
    /// 购物车(编辑)
    /// </summary>
    public class ShopCartEditDto
    {
        /// <summary>
        /// 商品货品ID
        /// </summary>
        [Display(Name = "商品货品")]
        public long ProductId { get; set; }

        /// <summary>
        /// 购买数量
        /// </summary>
        [Display(Name = "购买数量")]
        public int Quantity { get; set; } = 1;
    }

    /// <summary>
    /// 购物车(购买)
    /// </summary>
    public class ShopCartBuyDto
    {
        /// <summary>
        /// 商品ID
        /// </summary>
        [Display(Name = "商品ID")]
        public long GoodsId { get; set; }

        /// <summary>
        /// 商品货品ID
        /// </summary>
        [Display(Name = "商品货品")]
        public long ProductId { get; set; }

        /// <summary>
        /// 销售价格
        /// </summary>
        [Display(Name = "销售价格")]
        [Column(TypeName = "decimal(18, 2)")]
        public decimal SellPrice { get; set; }

        /// <summary>
        /// 购买数量
        /// </summary>
        [Display(Name = "购买数量")]
        public int Quantity { get; set; } = 1;
    }

    /// <summary>
    /// 购物车(分组列表)
    /// </summary>
    public class ShopCartListDto
    {
        // <summary>
        /// 所属商户ID
        /// </summary>
        [Display(Name = "所属商户")]
        public int MerchantId { get; set; }

        /// <summary>
        /// 商品标题
        /// </summary>
        [Display(Name = "店铺名称")]
        [StringLength(128)]
        public string? MerchantTitle { get; set; }

        /// <summary>
        /// 店铺头像
        /// </summary>
        [Display(Name = "店铺头像")]
        [StringLength(512)]
        public string? MerchantAvatar { get; set; }

        /// <summary>
        /// 店铺类型
        /// </summary>
        [Display(Name = "店铺类型")]
        [StringLength(128)]
        public string? StoreTitle { get; set; }

        /// <summary>
        /// 是否自营
        /// </summary>
        [Display(Name = "是否自营")]
        public byte IsSelf { get; set; } = 0;

        /// <summary>
        /// 购物车商品列表
        /// </summary>
        public ICollection<ShopCartDto> Goods { get; set; } = new List<ShopCartDto>();
    }

    /// <summary>
    /// 购物车(分组统计)
    /// </summary>
    public class ShopCartTotalListDto : ShopCartListDto
    {
        /// <summary>
        /// 商品总数量
        /// </summary>
        public int TotalQuantity { get; set; }

        /// <summary>
        /// 商品总重量(克)
        /// </summary>
        public int TotalWeight { get; set; }

        /// <summary>
        /// 所需兑换积分
        /// </summary>
        public int TotalPoint { get; set; } = 0;

        /// <summary>
        /// 商品应付金额
        /// </summary>
        [Column(TypeName = "decimal(18, 2)")]
        public decimal PayableAmount { get; set; } = 0;

        /// <summary>
        /// 商品实付金额
        /// </summary>
        [Column(TypeName = "decimal(18, 2)")]
        public decimal RealAmount { get; set; } = 0;

        /// <summary>
        /// 配送方式ID
        /// </summary>
        public int DeliveryId { get; set; } = 0;

        /// <summary>
        /// 配送方式标题
        /// </summary>
        public string? DeliveryTitle { get; set; }

        /// <summary>
        /// 实付总运费
        /// </summary>
        [Column(TypeName = "decimal(18, 2)")]
        public decimal FreightAmount { get; set; } = 0;

        /// <summary>
        /// 优惠券ID
        /// </summary>
        public long CouponId { get; set; } = 0;

        /// <summary>
        /// 优惠券标题
        /// </summary>
        public string? CouponTitle { get; set; }

        /// <summary>
        /// 优惠券金额
        /// </summary>
        [Column(TypeName = "decimal(18, 2)")]
        public decimal CouponAmount { get; set; } = 0;

        /// <summary>
        /// 促销活动金额
        /// </summary>
        public decimal PromotionAmount { get; set; } = 0;

        /// <summary>
        /// 订单实付金额
        /// </summary>
        public decimal OrderAmount { get; set; } = 0;

        /// <summary>
        /// 是否免运费(0否1是全部商品免运费)
        /// </summary>
        [Display(Name = "是否免运费")]
        public byte FreeFreight { get; set; } = 1;

        /// <summary>
        /// 用户留言
        /// </summary>
        [Display(Name = "用户留言")]
        public string? Postscript { get; set; }

        /// <summary>
        /// 促销活动信息
        /// </summary>
        public ShopPromotionDto? Promotion { get; set; }

        /// <summary>
        /// 会员可用优惠券列表
        /// </summary>
        public ICollection<ShopCouponHistoryCartDto> ShopCoupons = new List<ShopCouponHistoryCartDto>();

        /// <summary>
        /// 店铺配送方式列表
        /// </summary>
        public ICollection<ShopDeliveryCartDto> ShopDeliverys = new List<ShopDeliveryCartDto>();
    }

    /// <summary>
    /// 购物车(总统计)
    /// </summary>
    public class ShopCartTotalDto
    {
        /// <summary>
        /// 商品总数量
        /// </summary>
        public int TotalQuantity { get; set; }

        /// <summary>
        /// 兑换所需总积分
        /// </summary>
        public int TotalPoint { get; set; }

        /// <summary>
        /// 商品总实付金额
        /// </summary>
        [Column(TypeName = "decimal(18, 2)")]
        public decimal TotalRealAmount { get; set; } = 0;

        /// <summary>
        /// 运费总实付金额
        /// </summary>
        [Column(TypeName = "decimal(18, 2)")]
        public decimal TotalFreightAmount { get; set; } = 0;

        /// <summary>
        /// 优惠券总金额
        /// </summary>
        [Column(TypeName = "decimal(18, 2)")]
        public decimal TotalCouponAmount { get; set; } = 0;

        /// <summary>
        /// 活动优惠总金额
        /// </summary>
        [Column(TypeName = "decimal(18, 2)")]
        public decimal TotalPromotionAmount { get; set; } = 0;

        /// <summary>
        /// 订单总实付金额
        /// </summary>
        public decimal TotalOrderAmount { get; set; } = 0;

        /// <summary>
        /// 购物车统计列表
        /// </summary>
        public ICollection<ShopCartTotalListDto> List { get; set; } = new List<ShopCartTotalListDto>();
    }
}
